package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import db.operation.CRUD;
/**
 *丹书铁劵 请求所有的合同对应的servlet
 */
public class AllContractsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setDateHeader("Expires", 0);
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Pragma", "no-cache");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		HttpSession session = request.getSession();//new
		JSONArray records=new JSONArray();//new
		
		CRUD crud = new CRUD();
		String sql = request.getParameter("sql");
		System.out.println("获取到的sql语句是:"+sql);
		int business = Integer.parseInt(request.getParameter("business"));
		System.out.println("获取到的business是:"+business);
		
		JSONArray result = null;


		switch (business) {
		case 1:try {
				result=crud.getAllContracts(sql);
			} catch (SQLException e) {
				System.out.println("error:getAllContracts");
			}
			break;
		case 2:try {
				result=crud.getReserveHistory(sql);
			} catch (SQLException e) {
				System.out.println("error:getReserveHistory");
			}
			break;
		}
		System.out.println(result.toString());
		out.write(result.toString());
		
		
	}



	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
	

}
